import { request, type ApiResponse } from './request'

// 获取教师列表请求参数
export interface GetTeacherListRequest {
  teacherType: string
  name: string
}

// 教师列表项接口
export interface TeacherListItem {
  id?: number | string
  userId?: number
  teacherNum?: string
  name?: string
  nickname?: string
  username?: string
  password?: string
  email?: string
  phone?: string
  department?: string
  title?: string
  teacherType?: string
  roleId?: number | string
  status?: number | string
  createTime?: string
  updateTime?: string | null
  [key: string]: any
}

/**
 * 获取教师列表
 * @param data 查询参数
 * @returns Promise<ApiResponse<TeacherListItem[]>>
 */
export const getTeacherList = async (data: GetTeacherListRequest): Promise<ApiResponse<TeacherListItem[]>> => {
  return await request<TeacherListItem[]>('teacher/list', {
    method: 'POST',
    body: data
  })
}

// 添加教师请求参数
export interface CreateTeacherRequest {
  nickname: string
  email: string
  roleId: number
  className?: string
}

/**
 * 添加教师
 * @param data 教师信息
 * @returns Promise<ApiResponse<any>>
 */
export const createTeacher = async (data: CreateTeacherRequest): Promise<ApiResponse<any>> => {
  return await request<any>('teacher/add', {
    method: 'POST',
    body: data
  })
}

/**
 * 删除教师
 * @param userId 用户ID
 * @returns Promise<ApiResponse<any>>
 */
export const deleteTeacher = async (userId: number): Promise<ApiResponse<any>> => {
  return await request<any>('teacher/delete', {
    method: 'DELETE',
    params: { userId }
  })
}

/**
 * 根据用户ID获取教师信息
 * @param userId 用户ID
 * @returns Promise<ApiResponse<TeacherListItem>>
 */
export const getTeacherById = async (userId: number): Promise<ApiResponse<TeacherListItem>> => {
  return await request<TeacherListItem>(`teacher/getById/${userId}`, {
    method: 'GET'
  })
}

